#include <cstdint>
#include <iostream>
#include <istream>
#include <map>
#include <set>
#include <string>
using ll = int64_t;

ll n,m,l;
std::map<std::string,std::set<ll>> s;
std::string tmp;

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin>>n;
    for(ll i=1;i<=n;i++){
        std::cin>>l;
        for(ll j=1;j<=l;j++){
            std::cin>>tmp;
            s[tmp].insert(i);
        }
    }
    std::cin>>m;
    while(m--){
        std::cin>>tmp;
        if(std::map<std::string,std::set<ll>>::const_iterator p = s.find(tmp);p!=s.end()){
            for(const ll i:p->second){
                std::cout<<i<<" ";
            }
        }
        std::cout<<"\n";
    }
}